package com.i8office.android.zhihuixinwu.ui.schedule;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;

import com.cyan.tools.annotation.ActivityFragmentInject;
import com.cyan.tools.base.BaseActivity;
import com.gyf.barlibrary.ImmersionBar;
import com.i8office.android.zhihuixinwu.R;
import com.i8office.android.zhihuixinwu.event.RefreshLeaderEvent;
import com.i8office.android.zhihuixinwu.module.contract.CalendarContract;
import com.i8office.android.zhihuixinwu.module.presenter.ChooseLeaderPresenter;
import com.i8office.android.zhihuixinwu.widget.ItemDecoration;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import view.recyclerview.CommonAdapter;
import view.recyclerview.ViewHolder;

@ActivityFragmentInject(
        contentViewId = R.layout.activity_choose_leader,
        toolbarTitle = R.string.choose_leader
)
public class ChooseLeaderActivity extends BaseActivity<CalendarContract.ChooseLeaderPresenter> implements CalendarContract.ChooseLeaderView {
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    private CommonAdapter<LeaderData.LeaderBean> mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f) //原理：如果当前设备支持状态栏字体变色，会设置状态栏字体为黑色，如果当前设备不支持状态栏字体变色，会使当前状态栏加上透明度，否则不执行透明度
                .init();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new ItemDecoration(this, 1));
        mRecyclerView.setAdapter(mAdapter = new CommonAdapter<LeaderData.LeaderBean>(this, R.layout.item_text) {
            @Override
            protected void convert(ViewHolder holder, final LeaderData.LeaderBean item, int position) {
                holder.setText(R.id.text, item.name);
                holder.getConvertView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        RefreshLeaderEvent event = new RefreshLeaderEvent();
                        event.leaderBean = item;
                        EventBus.getDefault().post(event);
                        finish();
                    }
                });
            }
        });
        mPresenter = new ChooseLeaderPresenter(this);
        mPresenter.getLeadersData();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return false;
    }

    @Override
    public void showLeadersData(List<LeaderData.LeaderBean> data) {
        mAdapter.setList(data);
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }
}
